package com.jumi.microservice.api;

import com.alibaba.fastjson.JSONObject;
import com.jumi.microservice.common.base.dto.ResponseResult;
import com.jumi.microservice.common.utils.ResultGenerator;
import com.jumi.microservice.utils.OkHttpUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.Map;

@RestController
@RequestMapping("/api/ImApi")
@Api(tags = "C-客服相关接口")
public class ImApiController {

    @Autowired(required=false)
    RestTemplate restTemplate;

    @Value("${customer.unreadNumber}")
    private String url;


    @ApiOperation(value = "获取用户im客服系统未读消息数量",notes = "获取用户im客服系统未读消息数量")
    @ApiImplicitParam(name = "id", value = "用户id")
    @GetMapping("/getUnreadNumber")
    public ResponseResult AppArticleDetail(Long id){
        String booleanFuture = OkHttpUtils.httpGet(url+"?visiter_id="+id);
        Map maps = (Map)JSONObject.parse(booleanFuture);
        Integer data = 0;
        if(maps.get("code")!=null){
            if(0==(Integer) maps.get("code")){
                data = (Integer) maps.get("data");
            }
        }
        System.out.println("调用返回结果:"+data);
        return ResultGenerator.genSuccessResult(data);
    }
}
